package com.zpark.dao.impl;

import com.zpark.dao.IAccountDao;
import com.zpark.pojo.Account;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

import java.util.List;

/**
 * @PackageName: com.zpark.dao.impl
 * @ClassName: AccountDaoImpl
 * @Description: 自定义实现dao层接口（开发中不常用此方式）
 * @author: RZS
 * @date: 2023/4/20  10:03
 */
public class AccountDaoImpl implements IAccountDao {

    private SqlSessionFactory sqlSessionFactory;

    public void setSqlSessionFactory(SqlSessionFactory sqlSessionFactory) {
        this.sqlSessionFactory = sqlSessionFactory;
    }

    @Override
    public List<Account> findAll() {
        // 1、根据factory获取SqlSession对象
        SqlSession sqlSession = sqlSessionFactory.openSession();
        // 2、调用SqlSession中的方法，实现查询列表
        // 方法的参数为xml文件中mapper标签的namespace属性值.方法名字（sql标签的id值）
        List<Account> list = sqlSession.selectList("com.zpark.dao.IAccountDao.findAll");
        return list;
    }
}
